//
//  FontSetView.m
//  ebook
//
//  Created by 吴超飞 on 16/3/11.
//  Copyright © 2016年 Moton. All rights reserved.
//

#import "FontSetView.h"
#import "UIView+Extension.h"
#import "MTRotatingScreen.h"
#import "UIImage+RTTint.h"
#import "UIImage+Tint.h"


@interface FontSetView(){
    
    float systemLight;//初始的系统亮度
    CGFloat fontsize,lineSpace;
    UIButton *yanpizhi_btn,*yanhui_btn,*huyanlv_btn,*shushi_btn,*menghuan_btn;
    UIButton *linespace1_btn,*linespace2_btn,*linespace3_btn,*linespace4_btn;
    UIButton *fontSet_btn,*moreSet_btn;
    UILabel *lightLabel;
    float edgeLeft;

}

@property (nonatomic,retain) ReaderConfig *readerConfig;
@property (nonatomic,retain) UISlider *lightSlider;
@property (nonatomic,retain) UISegmentedControl *fontsizeSegment;
@property (nonatomic,retain) UIView *colorSelectView;
@property (nonatomic,retain) UIView *linespaceView;
@property (nonatomic,retain) UIView *setFounctionView;
@property (nonatomic,retain) SystemLightBtn *systemLightBtn;
@property (nonatomic,assign) float width;
@property (nonatomic,retain) UIColor *selectColor,*normalColor;

//land
@property (nonatomic,retain) UIView *landLightView;
@property (nonatomic,retain) UIView *landColorSelectView;
@property (nonatomic,retain) UIView *landLinespaceView;
@property (nonatomic,retain) UIView *landSettingView;

@end

@implementation FontSetView

-(instancetype)initWithReaderConfig:(ReaderConfig *)config{
    
    if (isIpad) {
        _width = 320 + 110;
        self = [super initWithFrame:CGRectMake(0, 0, _width, 235)];
    } else {
        _width = MTScreenW;
        self = [super initWithFrame:CGRectMake(0, 0, _width, 155)];
    }
    
    if (self) {
        systemLight = [UIScreen mainScreen].brightness;
        _readerConfig = config;
        fontsize = _readerConfig.FontSize;
        
        if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) || isIpad) {
            [self drawView];
        } else {
            _width = _width/5*4;
            edgeLeft = _width/10;
            [self drawLandscapeView];
        }
    }
    return self;
}

- (void)drawView {
    
    lightLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 30, 30)];
    lightLabel.text = @"亮度";
    lightLabel.textColor = self.normalColor;
    lightLabel.font = [UIFont systemFontOfSize:12];
    [self addSubview:lightLabel];
    
    if(!self.lightSlider)
        self.lightSlider = [[UISlider alloc] initWithFrame:CGRectMake(50, 10, _width - 50 - 100 , 30)];
    self.lightSlider.minimumValue = 0;
    self.lightSlider.maximumValue = 1;
    self.lightSlider.value = [UIScreen mainScreen].brightness;
    [self.lightSlider addTarget:self action:@selector(updateSliderValue:) forControlEvents:UIControlEventValueChanged];
    [self addSubview:self.lightSlider];
    
    [self addSubview:self.systemLightBtn];
    self.systemLightBtn.enabled = NO;
    self.systemLightBtn.isBeSelected = NO;
    
    if(!self.fontsizeSegment)
        self.fontsizeSegment = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"A-",@"A",@"A+", nil]];
    [self addSubview:self.fontsizeSegment];
    self.fontsizeSegment.frame = CGRectMake(20, CGRectGetMaxY(self.lightSlider.frame) + 20, _width - 20*2, 40);
    self.fontsizeSegment.backgroundColor = [UIColor clearColor];
    [self.fontsizeSegment setHighlighted:YES];
    [self.fontsizeSegment setImage:[UIImage imageNamed:@"font_size_minus"] forSegmentAtIndex:0];
    [self.fontsizeSegment setImage:[UIImage imageNamed:@"font_size_normal"] forSegmentAtIndex:1];
    [self.fontsizeSegment setImage:[UIImage imageNamed:@"font_size_add"] forSegmentAtIndex:2];
    [self.fontsizeSegment addTarget:self action:@selector(segmentValueChange:) forControlEvents:UIControlEventValueChanged];
    
    //背景颜色选择
    if (!_isNight) {//夜间模式时不可更换背景
        self.colorSelectView.y = CGRectGetMaxY(self.fontsizeSegment.frame) + 20;
        [self addSubview:self.colorSelectView];
        self.height += 70;
    }
    
    //行间距选择
    float liney = CGRectGetMaxY(_isNight?self.fontsizeSegment.frame:self.colorSelectView.frame)+20;
    self.linespaceView.y = liney;
    [self addSubview:self.linespaceView];
    
    //字体/更多设置
    self.setFounctionView.y = liney+CGRectGetHeight(self.linespaceView.frame);
    [self addSubview:self.setFounctionView];
    
    [self setIsNight:_isNight];//配色
}

-(UIButton *)systemLightBtn{
    if(!_systemLightBtn){
        _systemLightBtn = [[SystemLightBtn alloc] initWithFrame:CGRectMake(self.width-60-20, 12, 60, 25) titleColor:self.normalColor];
        [_systemLightBtn addTarget:self action:@selector(systemLightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _systemLightBtn;
}

-(void)systemLightBtnClick:(UIButton *)sender{
    
    self.lightSlider.value = systemLight;
    [self updateSliderValue:self.lightSlider];
}

-(UIColor *)normalColor{
    return  MTConfigColor(_isNight?@"MTReaderBar_NightNomarlText_Color":@"MTReaderBar_DayNomarlText_Color");
}

-(UIColor *)selectColor{
    return MTConfigColor(_isNight?@"MTReaderBar_NightSelected_Color":@"MTReaderBar_DaySelected_Color");
}

-(void)setIsNight:(BOOL)isNight{
    
    _isNight = isNight;
    if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)||isIpad) {
        if (_isNight) {
            self.height = 160+45;
            [self.colorSelectView removeFromSuperview];
            self.linespaceView.y = CGRectGetMaxY(self.fontsizeSegment.frame) + 20;
        }else{
            self.height = 220+55;
            self.colorSelectView.y = CGRectGetMaxY(self.fontsizeSegment.frame) + 20;
            [self addSubview:self.colorSelectView];
            self.linespaceView.y = CGRectGetMaxY(self.colorSelectView.frame) + 20;
        }
        self.setFounctionView.y = CGRectGetMaxY(self.linespaceView.frame)+10;
        [self setSelectColorBtn];
    } else {
        if (_isNight) {
            self.height = 110;
            [self.landColorSelectView removeFromSuperview];
            self.landLinespaceView.y = CGRectGetMaxY(self.landLightView.frame)+10;
            self.landSettingView.y = self.landLinespaceView.y;
        } else {
            self.height = 160;
            self.landColorSelectView.y = CGRectGetMaxY(self.landLightView.frame)+10;
            [self addSubview:self.landColorSelectView];
            self.landLinespaceView.y = CGRectGetMaxY(self.landColorSelectView.frame)+10;
            self.landSettingView.y = self.landLinespaceView.y;
        }
    }
    
    self.systemLightBtn.isNight = _isNight;
    
    UIColor *selectColor = self.selectColor;
    UIColor *normarlTextColor = self.normalColor;
    self.lightSlider.minimumTrackTintColor = selectColor;
    self.lightSlider.maximumTrackTintColor = normarlTextColor;
    [self.lightSlider setThumbImage:[[UIImage imageNamed:@"progress_dot_nl"] imageWithTintColor:selectColor] forState:UIControlStateNormal];
    self.fontsizeSegment.tintColor = normarlTextColor;
    
    [fontSet_btn setTitleColor:normarlTextColor forState:UIControlStateNormal];
    [fontSet_btn setTitleColor:selectColor forState:UIControlStateHighlighted];
    [moreSet_btn setTitleColor:normarlTextColor forState:UIControlStateNormal];
    [moreSet_btn setTitleColor:selectColor forState:UIControlStateHighlighted];
}

#pragma mark - 亮度调节
-(void)updateSliderValue:(id)sender{
    
    float value = ((UISlider*)sender).value;
    self.systemLightBtn.enabled = value!=systemLight;
    self.systemLightBtn.isBeSelected = value==systemLight;
    [[UIScreen mainScreen] setBrightness:value];
}

#pragma mark - 背景设置
-(UIView *)colorSelectView{
    
    if (!_colorSelectView) {
        _colorSelectView= [[UIView alloc] initWithFrame:CGRectMake(0, 0, _width, 50)];
        float width = _width/5;//CGRectGetWidth(_colorSelectView.frame)/5;
        yanpizhi_btn = [self colorSelectedButtonFrame:CGRectMake(0, 0, width, CGRectGetHeight(_colorSelectView.frame)) normalImage:@"color_yangpizhi" selectedImageName:@"color_yangpizhi_sl" withTag:1];
        [_colorSelectView addSubview:yanpizhi_btn];
        yanhui_btn = [self colorSelectedButtonFrame:CGRectMake(CGRectGetMaxX(yanpizhi_btn.frame), 0, width, CGRectGetHeight(_colorSelectView.frame)) normalImage:@"color_yanhui" selectedImageName:@"color_yanhui_sl" withTag:2];
        [_colorSelectView addSubview:yanhui_btn];
        huyanlv_btn = [self colorSelectedButtonFrame:CGRectMake(CGRectGetMaxX(yanhui_btn.frame), 0, width, CGRectGetHeight(_colorSelectView.frame)) normalImage:@"color_huyanlv" selectedImageName:@"color_huyanlv_sl" withTag:3];
        [_colorSelectView addSubview:huyanlv_btn];
        shushi_btn = [self colorSelectedButtonFrame:CGRectMake(CGRectGetMaxX(huyanlv_btn.frame), 0, width, CGRectGetHeight(_colorSelectView.frame)) normalImage:@"color_shushi" selectedImageName:@"color_shushi_sl" withTag:4];
        [_colorSelectView addSubview:shushi_btn];
        menghuan_btn = [self colorSelectedButtonFrame:CGRectMake(CGRectGetMaxX(shushi_btn.frame), 0, width, CGRectGetHeight(_colorSelectView.frame)) normalImage:@"color_menghuan" selectedImageName:@"color_menghuan_sl" withTag:5];
        [_colorSelectView addSubview:menghuan_btn];
        
        [self setSelectColorBtn];
    }
    
    return _colorSelectView;
}

//根据当前背景颜色选中对应的按钮
- (void)setSelectColorBtn{
    //根据以前的设置，初始化选中状态
    switch (_readerConfig.BgColorType) {
        case Yanhui_Color:
            [self selectColorBtn:yanhui_btn];
            break;
        case Yangpizhi_color:
            [self selectColorBtn:yanpizhi_btn];
            break;
        case Huyanlv_Color:
            [self selectColorBtn:huyanlv_btn];
            break;
        case Shushi_Color:
            [self selectColorBtn:shushi_btn];
            break;
        case Menghuan_Color:
            [self selectColorBtn:menghuan_btn];
            break;
        default:
            break;
    }
}

-(UIButton *)colorSelectedButtonFrame:(CGRect)frame normalImage:(NSString *)normalImageName selectedImageName:(NSString *)selectedImageName withTag:(NSInteger)tag{
    
    UIButton *btn = [[UIButton alloc] initWithFrame:frame];
    btn.tag = tag;
    btn.imageView.contentMode = UIViewContentModeScaleAspectFill;
    [btn setImage:[UIImage imageNamed:normalImageName] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:selectedImageName] forState:UIControlStateSelected];
    [btn addTarget:self action:@selector(colorSelectBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    return btn;
}

-(void)selectColorBtn:(UIButton *)btn{
    yanpizhi_btn.selected = btn.tag==1;
    yanhui_btn.selected = btn.tag==2;
    huyanlv_btn.selected = btn.tag==3;
    shushi_btn.selected = btn.tag==4;
    menghuan_btn.selected = btn.tag==5;
}

-(void)colorSelectBtnClick:(UIButton *)btn{
    
    [self selectColorBtn:btn];
    if ([self.delegate respondsToSelector:@selector(fontSetView:backgroudColor:)]) {
        [self.delegate fontSetView:self backgroudColor:(ReadBackgroud)(btn.tag-1)];
    }
}

#pragma mark - 行间距选择
-(UIView *)linespaceView{
    
    if (!_linespaceView) {
        _linespaceView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _width, 40)];
        
        float space = (_width - 20*2 - 60*4)/3;
        
        linespace1_btn = [self linespaceButtonFrame:CGRectMake(20, 0, 60, 40) imageName:@"linespace1" withTag:1];
        [_linespaceView addSubview:linespace1_btn];
        linespace2_btn = [self linespaceButtonFrame:CGRectMake(CGRectGetMaxX(linespace1_btn.frame)+space, 0, 60, 40) imageName:@"linespace2" withTag:2];
        [_linespaceView addSubview:linespace2_btn];
        linespace3_btn = [self linespaceButtonFrame:CGRectMake(CGRectGetMaxX(linespace2_btn.frame)+space, 0, 60, 40) imageName:@"linespace3" withTag:3];
        [_linespaceView addSubview:linespace3_btn];
        linespace4_btn = [self linespaceButtonFrame:CGRectMake(CGRectGetMaxX(linespace3_btn.frame)+space, 0, 60, 40) imageName:@"linespace4" withTag:4];
        [_linespaceView addSubview:linespace4_btn];
        
        switch (_readerConfig.LineSpace) {//根据之前的设置选中态
                
            case LINE_SPACE1:
                [self lineSpacingBtnclick:linespace1_btn];
                break;
            case LINE_SPACE2:
                [self lineSpacingBtnclick:linespace2_btn];
                break;
            case LINE_SPACE3:
                [self lineSpacingBtnclick:linespace3_btn];
                break;
            case LINE_SPACE4:
                [self lineSpacingBtnclick:linespace4_btn];
                break;
                
            default:
                break;
        }
    }
    
    return _linespaceView;
}

-(UIButton *)linespaceButtonFrame:(CGRect)frame imageName:(NSString *)imageName withTag:(NSInteger)tag{
    
    UIButton *btn = [[UIButton alloc] initWithFrame:frame];
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    btn.tag = tag;
    UIColor *color2 = MTConfigColor(_isNight?@"MTReaderBar_NightNomarlText_Color":@"MTReaderBar_DayNomarlText_Color");
    UIColor *color1 = MTConfigColor(_isNight?@"MTReaderBar_NightSelected_Color":@"MTReaderBar_DaySelected_Color");
    btn.layer.borderColor = btn.isSelected ? color1.CGColor:color2.CGColor;
    btn.layer.borderWidth = 1.0f;
    btn.layer.cornerRadius = 3.0f;
    [btn addTarget:self action:@selector(lineSpacingBtnclick:) forControlEvents:UIControlEventTouchUpInside];
    return btn;
}

-(void)lineSpacingBtnclick:(UIButton *)btn{
    
    UIColor *color2 = MTConfigColor(_isNight?@"MTReaderBar_NightNomarlText_Color":@"MTReaderBar_DayNomarlText_Color");
    UIColor *color1 = MTConfigColor(_isNight?@"MTReaderBar_NightSelected_Color":@"MTReaderBar_DaySelected_Color");
    
    linespace1_btn.layer.borderColor = btn.tag==1?color1.CGColor:color2.CGColor;
    linespace2_btn.layer.borderColor = btn.tag==2?color1.CGColor:color2.CGColor;
    linespace3_btn.layer.borderColor = btn.tag==3?color1.CGColor:color2.CGColor;
    linespace4_btn.layer.borderColor = btn.tag==4?color1.CGColor:color2.CGColor;
    
    float lineSpaceValue[4] = {LINE_SPACE1,LINE_SPACE2,LINE_SPACE3,LINE_SPACE4};
    if ([self.delegate respondsToSelector:@selector(fontSetView:linespace:)]) {
        [self.delegate fontSetView:self linespace:lineSpaceValue[btn.tag-1]];
    }
}

-(void)segmentValueChange:(UISegmentedControl *)sender{
    
    if (sender.selectedSegmentIndex == 2) {//字号加大
        if(fontsize<MaxTextFont)
            fontsize+=1;
    }else if(sender.selectedSegmentIndex == 0) {//字号变小
        if(fontsize>MinTextFont)
            fontsize-=1;
    }else if (sender.selectedSegmentIndex == 1){//常规字号
        fontsize = MTReaderDefaultFontsize;
    }
    
    if([self.delegate respondsToSelector:@selector(fontSetView:fontsizeSet:)]){
        [self.delegate fontSetView:self fontsizeSet:fontsize];
    }
    
    sender.selectedSegmentIndex = -1;
}

#pragma mark - 设置（字体，更多）
- (UIView *)setFounctionView {
    
    if (!_setFounctionView) {
        _setFounctionView = [[UIView alloc] init];
        _setFounctionView.frame = CGRectMake(0, 0, _width, 40);
        fontSet_btn = [self buttonFrame:CGRectMake(0, 0, _width/2, 40) title:@"字体设置>" tag:1];
        [_setFounctionView addSubview:fontSet_btn];
        
        UILabel *lineLabel = [[UILabel alloc] init];
        lineLabel.frame = CGRectMake(_width/2, CGRectGetMinY(fontSet_btn.frame)+15, 0.5, fontSet_btn.height-30);
        lineLabel.backgroundColor = MTConfigColor(@"MTReaderToolBar_toplineBg_Color");
        [_setFounctionView addSubview:lineLabel];
        
        moreSet_btn = [self buttonFrame:CGRectMake(_width/2, 0, fontSet_btn.width, fontSet_btn.height) title:@"更多设置>" tag:2];
        [_setFounctionView addSubview:moreSet_btn];
    }
    return _setFounctionView;
}

-(UIButton *)buttonFrame:(CGRect)frame title:(NSString *)title tag:(NSInteger)tag{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = frame;
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:MTConfigColor(_isNight?@"MTReaderBar_NightNomarlText_Color":@"MTReaderBar_DayNomarlText_Color") forState:UIControlStateNormal];
    [btn setTitleColor:MTConfigColor(_isNight?@"MTReaderBar_NightSelected_Color":@"MTReaderBar_DaySelected_Color") forState:UIControlStateHighlighted];
    btn.titleLabel.font = [UIFont systemFontOfSize:14.0];
    btn.tag = tag;
    btn.titleLabel.textAlignment = NSTextAlignmentCenter;
    [btn addTarget:self action:@selector(setBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    return btn;
}

-(void)setBtnClick:(UIButton *)btn {
    
    if ([self.delegate respondsToSelector:@selector(fontSetView:setBtnClick:)]) {
        [self.delegate fontSetView:self setBtnClick:btn.tag];
    }
}


#pragma mark - 横屏界面

- (void)drawLandscapeView {
    
    [self addSubview:self.landLightView];
    
    if(!self.fontsizeSegment)
        self.fontsizeSegment = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"A-",@"A",@"A+", nil]];
    self.fontsizeSegment.frame = CGRectMake(CGRectGetMaxX(self.landLightView.frame)+10, (self.landLightView.height-35)/2, _width/2 - 30, 35);
    self.fontsizeSegment.tintColor = MTConfigColor(@"MTReaderToolBar_fontSetSegmentTint_Color");
    self.fontsizeSegment.backgroundColor = [UIColor clearColor];
    [self.fontsizeSegment setHighlighted:YES];
    [self.fontsizeSegment setImage:[UIImage imageNamed:@"font_size_minus"] forSegmentAtIndex:0];
    [self.fontsizeSegment setImage:[UIImage imageNamed:@"font_size_normal"] forSegmentAtIndex:1];
    [self.fontsizeSegment setImage:[UIImage imageNamed:@"font_size_add"] forSegmentAtIndex:2];
    [self.fontsizeSegment addTarget:self action:@selector(segmentValueChange:) forControlEvents:UIControlEventValueChanged];
    [self addSubview:self.fontsizeSegment];
    
    //    //背景颜色选择
    if (!_isNight) {//夜间模式时不可更换背景
        self.landColorSelectView.y = CGRectGetMaxY(self.fontsizeSegment.frame) + 10;
        [self addSubview:self.landColorSelectView];
    }
    
    //行间距选择
    float liney = CGRectGetMaxY(_isNight?self.fontsizeSegment.frame:self.landColorSelectView.frame)+10;
    self.landLinespaceView.y = liney;
    [self addSubview:self.landLinespaceView];
    
    //    //字体/更多设置
    self.landSettingView.y = self.landLinespaceView.y;
    [self addSubview:self.landSettingView];
}

//横屏 亮度 设置
- (UIView *)landLightView {
    
    if (!_landLightView) {
        
        _landLightView = [[UIView alloc] initWithFrame:CGRectMake(edgeLeft, 0, _width/2-10, 50)];
        lightLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 30, 30)];
        lightLabel.text = @"亮度";
        lightLabel.textColor = self.normalColor;
        lightLabel.font = [UIFont systemFontOfSize:12];
        [_landLightView addSubview:lightLabel];
        
        if(!self.lightSlider)
            self.lightSlider = [[UISlider alloc] initWithFrame:CGRectMake(45, 10, _landLightView.width - 45 - 80, 30)];
        self.lightSlider.minimumValue = 0;
        self.lightSlider.maximumValue = 1;
        self.lightSlider.value = [UIScreen mainScreen].brightness;
        [self.lightSlider addTarget:self action:@selector(updateSliderValue:) forControlEvents:UIControlEventValueChanged];
        [_landLightView addSubview:self.lightSlider];
        
        [_landLightView addSubview:self.systemLightBtn];
        CGRect systemFrame = self.systemLightBtn.frame;
        systemFrame.origin.x = _landLightView.width - 60 - 15;
        self.systemLightBtn.frame = systemFrame;
        self.systemLightBtn.enabled = NO;
        self.systemLightBtn.isBeSelected = NO;
    }
    
    return _landLightView;
}

//横屏 背景设置
- (UIView *)landColorSelectView {
    
    if (!_landColorSelectView) {
        _landColorSelectView= [[UIView alloc] initWithFrame:CGRectMake(edgeLeft, 0, _width, 50)];
        float width = _landColorSelectView.width/5;//CGRectGetWidth(_colorSelectView.frame)/5;
        yanpizhi_btn = [self colorSelectedButtonFrame:CGRectMake(0, 0, width, CGRectGetHeight(_landColorSelectView.frame)) normalImage:@"color_yangpizhi" selectedImageName:@"color_yangpizhi_sl" withTag:1];
        [_landColorSelectView addSubview:yanpizhi_btn];
        yanhui_btn = [self colorSelectedButtonFrame:CGRectMake(CGRectGetMaxX(yanpizhi_btn.frame), 0, width, CGRectGetHeight(_landColorSelectView.frame)) normalImage:@"color_yanhui" selectedImageName:@"color_yanhui_sl" withTag:2];
        [_landColorSelectView addSubview:yanhui_btn];
        huyanlv_btn = [self colorSelectedButtonFrame:CGRectMake(CGRectGetMaxX(yanhui_btn.frame), 0, width, CGRectGetHeight(_landColorSelectView.frame)) normalImage:@"color_huyanlv" selectedImageName:@"color_huyanlv_sl" withTag:3];
        [_landColorSelectView addSubview:huyanlv_btn];
        shushi_btn = [self colorSelectedButtonFrame:CGRectMake(CGRectGetMaxX(huyanlv_btn.frame), 0, width, CGRectGetHeight(_landColorSelectView.frame)) normalImage:@"color_shushi" selectedImageName:@"color_shushi_sl" withTag:4];
        [_landColorSelectView addSubview:shushi_btn];
        menghuan_btn = [self colorSelectedButtonFrame:CGRectMake(CGRectGetMaxX(shushi_btn.frame), 0, width, CGRectGetHeight(_landColorSelectView.frame)) normalImage:@"color_menghuan" selectedImageName:@"color_menghuan_sl" withTag:5];
        [_landColorSelectView addSubview:menghuan_btn];
        
        [self setSelectColorBtn];
    }
    
    return _landColorSelectView;
}

//横屏 行间距设置
- (UIView *)landLinespaceView {
    
    if (!_landLinespaceView) {
        _landLinespaceView = [[UIView alloc] initWithFrame:CGRectMake(edgeLeft, 0, _width/2-10, 35)];
        
        float space = (_landLinespaceView.width - 50*4)/3;
        
        linespace1_btn = [self linespaceButtonFrame:CGRectMake(20, 0, 50, 35) imageName:@"linespace1" withTag:1];
        [_landLinespaceView addSubview:linespace1_btn];
        linespace2_btn = [self linespaceButtonFrame:CGRectMake(CGRectGetMaxX(linespace1_btn.frame)+space, 0, 50, 35) imageName:@"linespace2" withTag:2];
        [_landLinespaceView addSubview:linespace2_btn];
        linespace3_btn = [self linespaceButtonFrame:CGRectMake(CGRectGetMaxX(linespace2_btn.frame)+space, 0, 50, 35) imageName:@"linespace3" withTag:3];
        [_landLinespaceView addSubview:linespace3_btn];
        linespace4_btn = [self linespaceButtonFrame:CGRectMake(CGRectGetMaxX(linespace3_btn.frame)+space, 0, 50, 35) imageName:@"linespace4" withTag:4];
        [_landLinespaceView addSubview:linespace4_btn];
        
        switch (_readerConfig.LineSpace) {//根据之前的设置选中态
                
            case LINE_SPACE1:
                [self lineSpacingBtnclick:linespace1_btn];
                break;
            case LINE_SPACE2:
                [self lineSpacingBtnclick:linespace2_btn];
                break;
            case LINE_SPACE3:
                [self lineSpacingBtnclick:linespace3_btn];
                break;
            case LINE_SPACE4:
                [self lineSpacingBtnclick:linespace4_btn];
                break;
                
            default:
                break;
        }
    }
    
    return _landLinespaceView;
}

//横屏 （字体、更多）设置
- (UIView *)landSettingView {
    
    if (!_landSettingView) {
        _landSettingView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.landLinespaceView.frame), 0, _width/2-10, 40)];
        fontSet_btn = [self buttonFrame:CGRectMake(0, 0, _landSettingView.width/2, 40) title:@"字体设置>" tag:1];
        [_landSettingView addSubview:fontSet_btn];
        
        UILabel *lineLabel = [[UILabel alloc] init];
        lineLabel.frame = CGRectMake(_landSettingView.width/2, CGRectGetMinY(fontSet_btn.frame)+15, 0.5, fontSet_btn.height-30);
        lineLabel.backgroundColor = MTConfigColor(@"MTReaderToolBar_toplineBg_Color");
        [_landSettingView addSubview:lineLabel];
        
        moreSet_btn = [self buttonFrame:CGRectMake(_landSettingView.width/2, 0, fontSet_btn.width, fontSet_btn.height) title:@"更多设置>" tag:2];
        [_landSettingView addSubview:moreSet_btn];
    }
    return _landSettingView;
}


@end








//**************锁定按钮*****************//

@implementation SystemLightBtn

-(instancetype)initWithFrame:(CGRect)frame titleColor:(UIColor *)color{
    
    _color = color;
    if (self = [super initWithFrame:frame]) {
        self.titleLabel.font = [UIFont systemFontOfSize:12.0];
        self.layer.borderWidth = 1.0f;
        self.layer.cornerRadius = 3.0f;
        self.layer.borderColor = color.CGColor;
        self.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor;
        [self setTitle:@"系统" forState:UIControlStateNormal];
        [self setTitleColor:color forState:UIControlStateNormal];
    }
    return self;
}

-(void)setIsNight:(BOOL)isNight{
    _isNight = isNight;
    [self setIsBeSelected:_isBeSelected];
}

-(void)setIsBeSelected:(BOOL)isBeSelected{
    
    _isBeSelected = isBeSelected;
    UIColor *selectColorcolor = _isNight?MTColor(52, 52, 52, 1.0):MTColor(249, 249, 251, 1.0);
    UIColor *normalColor = _isNight?MTColor(60, 60, 60, 1.0):MTColor(230, 231, 237, 1.0);
    self.backgroundColor = _isBeSelected?selectColorcolor:normalColor;
    self.layer.borderColor = _isBeSelected?selectColorcolor.CGColor:normalColor.CGColor;
}

@end

